/*
* Copyright 2010 tekhniaG authors
*
* Licensed under the LGPL, Version 3.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.gnu.org/licenses/lgpl.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tekhnia.com.tgraphs.ui.validator
{
	import mx.validators.ValidationResult;
	import mx.validators.Validator;
	
	/**
	 * 
	 * Validates a value pair of type <Number>,<Number>
	 * 
	 */
	public class NumbersPairValidator extends Validator {
		/**
		 * 
		 * constructor that calls super's one
		 * 
		 */
		public function NumbersPairValidator() {
			super();
		}
		
		/**
		 * @override
		 * doValidation
		 * 
		 */
		override protected function doValidation(value: Object): Array {
			var str: String = value.toString();
			
			// create an array to return.
			var ValidatorResults: Array = new Array();
			// Call base class doValidation().
			ValidatorResults = super.doValidation(value);       
			// Return if there are errors.
			if (ValidatorResults.length > 0)
				return ValidatorResults;
			
			if (str.length == 0)
				return ValidatorResults;
			
			var re: RegExp = /\-?\d+\.?\d*\,\-?\d+\.?\d*/g;
			var rStr: String = str.replace(re, "");
			if (rStr.length != 0) {
				var vResult: ValidationResult = new ValidationResult(true, null, "PairValueError","Format: %f,%f");
				ValidatorResults.push(vResult);
				return ValidatorResults;
			}
			return ValidatorResults;
		}
	}
}